
(* Error localization *)
type localization = {
	pos_start : Lexing.position;
	pos_end : Lexing.position
}

(* Functions and programs *)
type program = sourceElement list

and sourceElement = 
	| AStatement of statement
	(*| AFunctionDeclaration of functionDeclaration *) (* Modif #1 *)

and functionDeclaration = is_private * is_meta * is_inline * identifier * (formalParameter list) * functionBody

and functionExpression = is_inline * (identifier option) * (formalParameter list) * functionBody

and functionBody = sourceElement list

and formalParameter = identifier

(* Statements *)
and block = statement list

and statement = 
	| ABlock of block
	| AOperatorAssignment of operatorAssignment
	| AOperatorUnassignment of operatorUnassignment
	| AVariableStatement of variableStatement
	| AConstStatement of constStatement
	| AFuncDeclaration of functionDeclaration	(* Modif #1 *)
	| AClassStatement of classStatement
	| AEmptyStatement
	| AExpressionStatement of expressionStatement
	| AIfStatement of ifStatement
	| AIterationStatement of iterationStatement
	| AContinueStatement of continueStatement
	| ABreakStatement of breakStatement
	| AReturnStatement of returnStatement
	| AWithStatement of withStatement
	| ALabelledStatement of labelledStatement
	| ASwitchStatement of switchStatement
	| AThrowStatement of throwStatement
	| ATryStatement of tryStatement
	| ADebuggerStatement

and identifier = string

and variableStatement = is_private * is_meta * (variableDeclaration list)

and operatorAssignment = string * assignmentExpression

and operatorUnassignment = string

and is_inline = bool

and is_private = bool

and is_meta = bool

and classStatement = is_private * is_meta * identifier * ((string list) option) * (classElement list)

and classElement =
	| ACVariableStatement of variableStatement
	| ACConstStatement of constStatement
	| ACFuncDeclaration of functionDeclaration

and constStatement = is_private * is_meta * (variableDeclaration list)

and variableDeclaration = identifier * (initializer_type option)

and initializer_type = assignmentExpression

and expressionStatement = expression

and ifStatement =
	| AIfElse of expression * statement * statement
	| AIf of expression * statement


and iterationStatement =
	| ADoWhile of statement * expression
	| AWhile of expression * statement
	| AFor of (expression option) * (expression option) * (expression option) * statement
	| AForVar of is_meta * (variableDeclaration list) * (expression option) * (expression option) * statement
	| AForIn of leftHandSideExpression * expression * statement
	| AForVarIn of is_meta * variableDeclaration * expression * statement

and continueStatement = identifier option

and breakStatement = identifier option

and returnStatement = expression option

and withStatement = expression * statement

and switchStatement = expression * caseBlock

and caseBlock = 
	| ACasesNoDefault of caseClause list
	| ACasesDefault of (caseClause list) * defaultClause * (caseClause list)

and caseClause = expression * (statement list)

and defaultClause = statement list

and labelledStatement = identifier * statement 

and tryStatement = 
	| ATryCatch of block * catch
	| ATryFinally of block * finally
	| ATryCatchFinally of block * catch * finally

and catch = identifier * block

and finally = block

and throwStatement = expression

(* Literals *)
and literal =
	| ANull
	| ABooleanLiteral of bool
	| ALitNumericLiteral of string
	| ALitStringLiteral of string
	| ARegularExpressionLiteral of regularExpression

and regularExpression = string * string

(* Expressions *)
and primaryExpression =
	| AThis
	| AIdentifier of identifier
	| ALiteral of literal
	| AArrayLiteral of arrayLiteral
	| AObjectLiteral of objectLiteral
	| AExpression of expression

and arrayLiteral =
	| AElisions of elision list
	| AElements of element list
	| AElementsAndElisions of (element list) * (elision list)

and elision = AElision

and element = (elision list) * assignmentExpression

and objectLiteral = propertyAssignment list

and propertyAssignment =
	| APropAssignment of propertyName * assignmentExpression
	| APropGet of propertyName * functionBody
	| APropSet of propertyName * (identifier list) * functionBody

and propertyName =
	| AIdentifierName of string
	| AStringLiteral of string
	| ANumericLiteral of string

and memberExpression =
	| APrimaryExpr of primaryExpression
	| AFunctionExpr of functionExpression
	| AMemberBracketExpr of memberExpression * expression
	| AMemberDotExpr of memberExpression * string
	| AMemberNewExpr of memberExpression * (argument list)

and newExpression =
	| AMemberExpression of memberExpression
	| ANewMemberExpression of newExpression

and callExpression =
	| ACallMemberArgs of memberExpression * (argument list)
	| ACallExpressionArgs of callExpression * (argument list)
	| ACallExpressionExpr of callExpression * expression
	| ACallExpressionIdent of callExpression * string

and argument = assignmentExpression

and leftHandSideExpression =
	| ANewExpression of newExpression
	| ACallExpression of callExpression

and postfixExpression =
	| ALeftHandSide of leftHandSideExpression
	| ALeftHandSideOp of leftHandSideExpression * string

and unaryExpression =
	| APostfixExpr of postfixExpression
	| AOpUnaryExpr of string * unaryExpression

and binaryExpression = 
	| AUnaryExpr of unaryExpression
	| ABinaryExpr of string * binaryExpression * binaryExpression

and conditionalExpression = 
	| ACondBinaryExpr of binaryExpression
	| ACondTernaryExpr of binaryExpression * assignmentExpression * assignmentExpression

and assignmentExpression =
	| ACondExpr of conditionalExpression
	| AAssignOp of leftHandSideExpression * string * assignmentExpression

and expression = assignmentExpression list

